var fs = require('fs');
var readline = require('readline');
var stream = require('stream');

var list = require('../model').list;
var util = require('../util');

var streamFile = function (filename) {
    var inStream = fs.createReadStream(filename);
    // var outStream = new stream;
    // return readline.createInterface(inStream, outStream);
    return readline.createInterface(inStream);
}

var rl = streamFile('../log/app.log');

var i = 0;
var startTime, stopTime;

var date1 = new Date();
startTime = date1.toLocaleString() + '.' + (date1.getMilliseconds() + 1000).toString().slice(1);

rl.on('line', function (line) {
    var data = line.toString();

    if (data) {
        // console.log(data);
    }
    else {
        console.log('\n总共输出了' + (i - 1) + '行');
        rl.close();
    }
    i++;
});

rl.on('close', function () {
    var date2 = new Date();
    stopTime = date2.toLocaleString() + '.' + (date2.getMilliseconds() + 1000).toString().slice(1);
    console.log('\n输出结束！');
    console.log('\n总共输出了' + (i - 1) + '行');

    console.log('开始时间：' + startTime);
    console.log('结束时间：' + stopTime);
    console.log('运行时间：%d', date2 - date1);
    // process.exit(0);   //加上这一行可以强行结束程序，否则还会继续输出接下来的3,4,5,6直到最后一行。
});